import request from '@/utils/request'

export default {
  getOrderList(searchModel) {
    let params = '&pageNo=' + searchModel.pageNo + '&pageSize=' + searchModel.pageSize
    params =
      searchModel.userId === '' ||
      searchModel.userId === null ||
      searchModel.userId === undefined
        ? params
        : params + '&userId=' + searchModel.userId
    params =
      searchModel.orderType === '' ||
      searchModel.orderType === null ||
      searchModel.orderType === undefined
        ? params
        : params + '&orderType=' + searchModel.orderType
    return request({
      url: '/order/list?' + params,
      method: 'get'

      // params:{
      //   pageNo:searchModel.pageNo,
      //   pageSize:searchModel.pageSize,
      //   username:searchModel.username,
      //   orderType:searchModel.orderType
      // }
    })
  },
  addOrder(order) {
    return request({
      url: '/order/addOrder',
      method: 'post',
      data: order
    })
  },
  updateOrder(order) {
    return request({
      url: '/order/updateOrder',
      // method: 'put',
      method: 'post',
      data: order
    })
  },
  saveOrder(order) {
    if (order.orderId == null || order.orderId === undefined) {
      return this.addOrder(order)
    }
    return this.updateOrder(order)
  },
  getOrderById(orderId) {
    let params = ''
    params =
      orderId === '' ||
      orderId === null ||
      orderId === undefined
        ? params
        : orderId
    return request({
      // url: '/order/'+id,
      url: `/order/getOrderById/` + params,
      method: 'get'
    })
  },
  deleteById(orderId) {
    return request({
      url: `/order/deleteOrderById`,
      method: 'delete',
      params: {
        deleteOrderId: orderId
      }
    })
  }

}
